package com.ta.gulimall.ware.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.ta.gulimall.ware.dao.WareSkuDao;
import com.ta.gulimall.ware.view.vo.LockStoreRespVo;
import com.ta.gulimall.ware.view.vo.LockStoreVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.ta.gulimall.ware.view.entity.WareSkuEntity;
import com.ta.gulimall.ware.service.WareSkuService;
import com.ta.gulimall.common.utils.system.PageUtils;
import com.ta.gulimall.common.utils.system.R;



/**
 * 商品库存
 *
 * @author tuao
 * @email tuaoo@gmail.com
 * @date 2022-10-29 10:38:36
 */
@RestController
@RequestMapping("ware/waresku")
public class WareSkuController {
    @Autowired
    private WareSkuService wareSkuService;

    /**
     * sku商品库存
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = wareSkuService.pageWareSkus(params);

        return R.ok().put("page", page);
    }

    /**
     * 查询skuIds下的库存数
     * @param skuIds
     * @return
     */
    @PostMapping("/listSkuWare")
    public R listSkuWare(@RequestBody List<Long> skuIds){
        Map<Long, Long> wareSkuEntities = wareSkuService.mapSkuWare(skuIds);

        return R.ok(wareSkuEntities);
    }

    /**
     * 锁定库存
     * @param lockStoreVo
     * @return
     */
    @PostMapping("/lockStore")
    public R lockStore(@RequestBody LockStoreVo lockStoreVo){
        LockStoreRespVo lockStoreRespVo = wareSkuService.lockStore(lockStoreVo);
        return R.ok(lockStoreRespVo);
    }

    /**
     * 解锁库存
     * @param lockStoreRespVo
     * @return
     */
    @PostMapping("/unlockStore")
    public R unlockStore(@RequestBody LockStoreRespVo lockStoreRespVo){
        wareSkuService.unlockStore(lockStoreRespVo);
        return R.ok();
    }




    //================以下是系统代码=================
    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		WareSkuEntity wareSku = wareSkuService.getById(id);

        return R.ok().put("wareSku", wareSku);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody WareSkuEntity wareSku){
		wareSkuService.save(wareSku);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody WareSkuEntity wareSku){
		wareSkuService.updateById(wareSku);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		wareSkuService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
